import { createRouter, createWebHashHistory } from 'vue-router'

// 定义路由信息数组
const routes = [
  // 首页
  {
    Path: '/',
    name: '404',
    component: () => import('../components/404.vue'),
    redirect: '/login',
  },
  // 登录页
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue'),
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/Register.vue'),
  },
  {
    Path: '/index',
    name: 'Index',
    redirect: '/welcome',
    component: () => import('../views/Index.vue'),
    children: [
      {
        path: '/welcome',
        name: 'Welcome',
        component: () => import('../components/Welcome.vue'),
      },
      {
        path: '/view',
        name: 'View',
        component: () => import('../components/view.vue'),
      },
      {
        path: '/date',
        name: 'Date',
        component: () => import('../components/date.vue'),
      },
      {
        path: '/teststart',
        name: 'Teststart',
        component: () => import('../components/test/teststart.vue'),
      },
      {
        path: '/test',
        name: 'Test',
        component: () => import('../components/test/test.vue'),
      },
      {
        path: '/testover',
        name: 'Testover',
        component: () => import('../components/test/testover.vue'),
      },
      {
        path: '/select',
        name: 'Select',
        component: () => import('../components/select.vue'),
      },
      {
        path: '/INTJ',
        name: 'MBTI-INTJ',
        component: () => import('../components/mbti/intj.vue'),
      },
      {
        path: '/INTP',
        name: 'MBTI-INTP',
        component: () => import('../components/mbti/intp.vue'),
      },
      {
        path: '/ENTJ',
        name: 'MBTI-ENTJ',
        component: () => import('../components/mbti/entj.vue'),
      },
      {
        path: '/ENTP',
        name: 'MBTI-ENTP',
        component: () => import('../components/mbti/entp.vue'),
      },
      {
        path: '/INFJ',
        name: 'MBTI-INFJ',
        component: () => import('../components/mbti/infj.vue'),
      },
      {
        path: '/INFP',
        name: 'MBTI-INFP',
        component: () => import('../components/mbti/infp.vue'),
      },
      {
        path: '/ENFJ',
        name: 'MBTI-ENFJ',
        component: () => import('../components/mbti/enfj.vue'),
      },
      {
        path: '/ENFP',
        name: 'MBTI-ENFP',
        component: () => import('../components/mbti/enfp.vue'),
      },
      {
        path: '/ISTJ',
        name: 'MBTI-ISTJ',
        component: () => import('../components/mbti/istj.vue'),
      },
      {
        path: '/ISFJ',
        name: 'MBTI-ISFJ',
        component: () => import('../components/mbti/isfj.vue'),
      },
      {
        path: '/ESTJ',
        name: 'MBTI-ESTJ',
        component: () => import('../components/mbti/estj.vue'),
      },
      {
        path: '/ESFJ',
        name: 'MBTI-ESFJ',
        component: () => import('../components/mbti/esfj.vue'),
      },
      {
        path: '/ISTP',
        name: 'MBTI-ISTP',
        component: () => import('../components/mbti/istp.vue'),
      },
      {
        path: '/ISFP',
        name: 'MBTI-ISFP',
        component: () => import('../components/mbti/isfp.vue'),
      },
      {
        path: '/ESTP',
        name: 'MBTI-ESTP',
        component: () => import('../components/mbti/estp.vue'),
      },
      {
        path: '/ESFP',
        name: 'MBTI-ESFP',
        component: () => import('../components/mbti/esfp.vue'),
      },
    ],
  },
]

// 创建一个路由器对象
const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

// 导入nprogress
import NProgress from 'nprogress'
// 导入nprogress的样式
import 'nprogress/nprogress.css'

// 定义路由导航前置守卫
router.beforeEach((to, form, next) => {
  NProgress.start()
  next()
})
// 定义路由导航后置守卫
router.afterEach(() => {
  NProgress.done()
})

export default router
